package com.mashibing.springbootdatasourcedemo2.controller;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import javax.xml.ws.RequestWrapper;
import java.sql.Connection;
import java.sql.SQLException;

/** datasource测试
 * <简述>
 * <详细描述>
 *
 * @author LiuShanshan
 * @version $Id$
 */
@RestController           // 必须要使用RestController，不能直接使用controller
public class DataSourceTest {
    @Autowired
    private DataSource dataSource;

    /**
     *<简述> 默认数据源测试
     *<详细描述>
     * @author Liushanshan
     * @param
     * @return void
    */
    @RequestMapping("/datasource")
    public void datasourceTest() throws SQLException {
        Connection connection = dataSource.getConnection();     // 默认数据源是class com.zaxxer.hikari.HikariDataSource
        System.out.println(connection);
        DruidDataSource druidDataSource = (DruidDataSource)dataSource;
        System.out.println("==============");
        System.out.println(druidDataSource.getConnectCount());
        System.out.println(druidDataSource.getDestroyCount());
    }


}
